<template>
  <div class="search-nav">
    <el-form :inline="true" :model="formInline" class="form-inline">
      <el-form-item label="工程名称：">
        <el-input
          class="innerInput"
          v-model="formInline.projectName"
          placeholder="--请输入--"
          size="large"
          input-style
        />
      </el-form-item>
      <el-form-item
        label="管线类型："
        style="margin-left: 20px; margin-right: 20px"
        class="inputDeep"
      >
        <el-select
          v-model="formInline.type"
          class="m-2"
          placeholder="--请选择--"
        >
          <el-option
            v-for="item in typeOption"
            :key="item"
            :label="item===null?'':item.type"
            :value="item===null?'':item.type"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申报时间：">
        <el-date-picker
          v-model="formInline.times"
          type="datetimerange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="small"
          value-format="YYYY-MM-DD HH:mm:ss"
          @change="change"
        />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="onClear">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref, defineEmits, onMounted } from 'vue'
import { pipeLineApplyType } from '@/api/pipeline'

const typeOption = ref({})
const formInline = reactive({
  projectName: '',
  type: '',
  startDate: '',
  endDate: ''
})

const change = (options) => {
  formInline.startDate = options[0]
  formInline.endDate = options[1]
}
const getPipeType = async () => {
  const res = await pipeLineApplyType()
  typeOption.value = res
  // console.log(typeOption.value)
}
getPipeType()

const emits = defineEmits(['onSearch'])
const onSubmit = () => {
  emits('onSearch', formInline)
}

const onClear = () => {
  formInline.projectName = ''
  formInline.type = ''
  formInline.startDate = ''
  formInline.endDate = ''
  emits('onSearch', formInline)
}
</script>

<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  :deep(.inputDeep .el-input__inner) {
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.39);
    width: 215px;
    height: 36px;
  }
  .btns {
    margin-left: 170px;
  }
}
</style>
